package com.market.service.wx.impl;

import com.market.bean.MarketKeyword;
import com.market.bean.MarketKeywordExample;
import com.market.bean.MarketSearchHistory;
import com.market.bean.MarketSearchHistoryExample;
import com.market.bean.common.BaseRespVo;
import com.market.bean.vo.wx.SearchIndexVo;
import com.market.mapper.MarketKeywordMapper;
import com.market.mapper.MarketSearchHistoryMapper;
import com.market.mapper.MarketTopicMapper;
import com.market.service.wx.WxSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @author wh194@foxmail.com
 * @since 2023/01/02 23:04
 */
@Service
public class WxSearchServiceImpl implements WxSearchService {
    @Autowired
    // MarketSearchHistory marketSearchHistoryMapper;
    MarketSearchHistoryMapper marketSearchHistoryMapper;

    @Autowired
    MarketKeywordMapper marketKeywordMapper;


    @Override
    public SearchIndexVo index() {
        SearchIndexVo searchIndexVo = new SearchIndexVo();

        MarketKeywordExample defaultMarketKeywordExample = new MarketKeywordExample();

        defaultMarketKeywordExample.createCriteria().andIsDefaultEqualTo(true).andDeletedEqualTo(false);
        List<MarketKeyword> defaultMarketKeyword = marketKeywordMapper.selectByExample(defaultMarketKeywordExample);

        searchIndexVo.setDefaultKeyword(defaultMarketKeyword.get(0));

        MarketKeywordExample historyMarketKeywordExample = new MarketKeywordExample();
        historyMarketKeywordExample.createCriteria().andIsHotEqualTo(false).andDeletedEqualTo(false);

        List<MarketKeyword> historyMarketKeyword = marketKeywordMapper.selectByExample(historyMarketKeywordExample);


        MarketKeyword[] temp =  new MarketKeyword[historyMarketKeyword.size()];
        MarketKeyword[] historyMarketKeywordArray = historyMarketKeyword.toArray(temp);
        searchIndexVo.setHistoryKeywordList(historyMarketKeywordArray);

        MarketKeywordExample hotMarketKeywordExample = new MarketKeywordExample();
        hotMarketKeywordExample.createCriteria().andIsHotEqualTo(true).andDeletedEqualTo(false);

        List<MarketKeyword> hotMarketKeyword = marketKeywordMapper.selectByExample(hotMarketKeywordExample);


        MarketKeyword[] temp2 = new MarketKeyword[hotMarketKeyword.size()];
        MarketKeyword[] hotMarketKeywordArray = hotMarketKeyword.toArray(temp2);

        searchIndexVo.setHotKeywordList(hotMarketKeywordArray);

        return searchIndexVo;
    }
}
